package com.ajhlp.spring_modules.web.controller;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/editor")
public class EditorContentReceiveController {

	@RequestMapping(method=RequestMethod.POST,value="/save")
	public void receiveHTMLContent(String content, HttpServletRequest request, HttpServletResponse response){
		try {
			FileUtils.write(new File("/home/ajhlp/save.html"), content, "UTF-8");
			
			response.getWriter().write("saved success!");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
